package com.neusoft.training.podcast.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.neusoft.training.podcast.entity.Category;
import com.neusoft.training.podcast.entity.Video;
import com.neusoft.training.podcast.service.CategoryService;

@Controller
public class CategoryController {
	
	@Autowired
	private CategoryService categoryService;
	
	@RequestMapping("/categoryList")
	public ModelAndView listCategories(ModelAndView mv) {
		List<Category> categories = categoryService.findAllCategories();
		
		mv.addObject("categories",categories );
		mv.setViewName("categoryMg");
		return mv;
	}
	
	@RequestMapping("/addVideoMg")
	public ModelAndView listCategoriesForVideo(ModelAndView mv) {
		
		List<Category> categories = categoryService.findAllCategories();
		mv.addObject("categories",categories );
		mv.setViewName("videoMg_add");
		return mv;
	}
	
	@RequestMapping("/addCategory")
	public String addCategory(String categoryName, String type) {
		categoryService.addCategory(categoryName, type);
		return "redirect:/categoryList";
	}
	
	@RequestMapping("/deleteCategory")
	public @ResponseBody String deleteCategory(Integer categoryID){
		
		categoryService.deleteCategory(categoryID);
		
		return "delete_success";
		
	}
	

}
